//
//  ChatListViewController.m
//  Gunz
//
//  Created by Joggy on 16/3/9.
//  Copyright © 2016年 NUPT. All rights reserved.
//

#import "ChatListViewController.h"
#import "ChatListViewCell.h"

@interface ChatListViewController ()

@end

ChatListViewCell *cell;

@implementation ChatListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self prepareForNav];
    [self prepareForLayout];
}

- (void)prepareForNav {
    [super prepareForNav];
    //返回按键
    UIImage *leftImage = [UIImage imageNamed:@"all_back"];
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, (leftImage.size.width/leftImage.size.height)*22, 22)];
    [leftButton setImage:leftImage forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    [self navigationItem].leftBarButtonItem = leftBarItem;
}

- (void)prepareForLayout {
    [super prepareForLayout];
    table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight - 64)];
    table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    table.backgroundColor = [UIColor clearColor];
    table.tableFooterView = [[UIView alloc] init];
    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];
    cell = [[ChatListViewCell alloc] init];
    [table registerClass:cell.class forCellReuseIdentifier:@"reuseCell"];
}

#pragma 事件方法

- (void)back {
    [self.navigationController popViewControllerAnimated:true];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma 代理方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    RCConversationViewController *chatView = [[RCConversationViewController alloc] init];
    chatView.conversationType = ConversationType_PRIVATE;
    chatView.targetId = @"3744";
    chatView.title = @"会话";
    [self.navigationController pushViewController:chatView animated:true];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return CLCellHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ChatListViewCell *cell = (ChatListViewCell*)[tableView dequeueReusableCellWithIdentifier:@"reuseCell"];
    cell.chatTarget.text = @"用户";
    cell.lastMassage.text = @"最后的消息。。。";
    return cell;
}

@end




